<template>
  <el-dialog :title="'选择机构分组'" :close-on-click-modal="false" :visible.sync="visible" width="800px"
             @close="clearDataList()" append-to-body>
    <div>
      <el-table :data="fzData" @selection-change="handleSelectionChange" class="avue-crud">
        <el-table-column :selectable="checkSelect" type="selection" width="55px" ></el-table-column>
        <el-table-column prop="" label="序号" :formatter="nShowIndex"></el-table-column>
        <el-table-column prop="jgFzName" label="名称"></el-table-column>
        <el-table-column prop="jgFzSm" label="说明"></el-table-column>
      </el-table>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="btnSave">确定</el-button>
      <el-button @click="clearDataList" type="primary" plain>取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {getJgfzList} from '@/api/jiangjin/jiangjinjjjgfz'

export default {
  created() {
    this.multipleSelection = [];
  },
   data(){
     return{
       visible:false,
       deptId:'',
       fzData:[],
       multipleSelection: [],
       SelectJgStr:""
     }
   },
   methods:{
     init(deptId,selectJg){
       this.visible = true;
       this.deptId = deptId;
       //console.log(deptId);
       this.SelectJgStr = "";
       this.SelectJgStr = selectJg;
      this.getJgfzListOption();
     },
     nShowIndex(row, column, cellValue, index){
       return index + 1;
     },
     handleSelectionChange(val) {
       this.multipleSelection = val;
     },
     // 取得分组数组
     getJgfzListOption() {
       getJgfzList(this.deptId).then(res => {
         this.fzData = res.data.data;
         ////console.log(this.fzData);
       });
     },
     clearDataList(){
       this.fzData = [];
       this.multipleSelection = [];
       this.SelectJgStr = "";
       this.visible = false;
     },
     checkSelect (row,index) {
       let isCheck = false;
       if(this.SelectJgStr.indexOf(row.id) === -1){
         isCheck = true;
       }
       return isCheck;
     },
     btnSave(){
       this.$emit("getChildValue",this.multipleSelection);
       this.clearDataList();
     }
   }
}
</script>

<style scoped>

</style>
